mk = angular.module('myapp', ['ngRoute']);
mk.config(function($routeProvider) {
	$routeProvider.when('/a', {
		templateUrl: 'shouye.html',
	}).when('/b', {
		templateUrl: 'gouwuche.html',
	}).otherwise({
		redirectTo: '/a',
	})
})

mk.controller('shouye', ['$scope', '$http', function($scope, $http) {
	$http.get('http://127.0.0.1:8080').then(function(res) {
		$scope.waimai = res.data.waimai;
	})
	$scope.arr = [];
	$scope.shuliang = 0;
	$scope.zong = 0;
	$scope.dian = function(xb) {
		//数量
		$scope.shuliang++;
		console.log($scope.shuliang)
		//分数
		$scope.waimai[xb].fenshu++;
		
		//总价
		$scope.zong += $scope.waimai[xb].price;
		console.log($scope.zong)
		$scope.arr.push($scope.waimai[xb])
		console.log($scope.arr)
		for(var i = 0; i < $scope.arr.length; i++) {
			console.log($scope.arr.length)
			for(var j = i + 1; j < $scope.arr.length; j++) {
				if($scope.arr[i] == $scope.arr[j]) {
					$scope.arr.splice(i, 1);
					j--;
				}
			}
		}
	}
	$scope.qing = function() {
		$scope.shuliang = 0;
		$scope.arr = [];
		$scope.zong = 0;
		angular.forEach($scope.waimai,function(val,key){
			val.fenshu=0;
		})
	}
}])